<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 100%; overflow-y: hidden"
  >
    <template slot="footer">
      <a-button key="back" v-if="isReadOnly" @click="handleCancel">关闭</a-button>
    </template>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-spin :spinning="confirmLoading">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="单据编号" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
                <a-input placeholder="请输入单据编号查询" v-model="queryParam.number"></a-input> 
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="10">
              <a-form-item label="单据日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 210px"
                  v-model="queryParam.createTimeRange"
                  format="YYYY-MM-DD"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChange"
                  @ok="onDateOk"
                />
              </a-form-item>
            </a-col>
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :md="6" :sm="24">
                <a-button type="primary" @click="searchQuery(1)">查询</a-button>
                <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              </a-col>
            </span>
          </a-row>
        </a-form>
      </a-spin>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin-top: 5px">
      <a-button v-if="btnEnableList.indexOf(1) > -1" @click="onClick" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" v-if="btnEnableList.indexOf(1) > -1" @click="batchDel"
            ><a-icon type="delete" />删除</a-menu-item
          >
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /> </a-button>
      </a-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource2"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">

          <a @click="onClickss(record)">查看</a>
          <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />
          <a-popconfirm v-if="btnEnableList.indexOf(1) > -1" title="确定删除吗?" @confirm="handleDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <SaleOutModal1 ref="SaleOutModal1"  v-if="visibles"  :visibles="visibles"  @guanb="guanb" :idss="idss" :pid="id"/>
<!--    <SaleOutModal2 ref="SaleOutModal2"  v-if="visible1"  :visible1="visible1"  @guan="guan" :idone="idone" :headerIds="headerIds" />-->
    <bill-detail3 ref="modalDetail" v-if="visible1"  :visible="visible1" :billType="'销售出库'" @guan="guan" ></bill-detail3>
  </a-modal>
</template>
<script>
import SaleOutModal1 from './SaleOutModal1'
import SaleOutModal2 from '../../bill/modules/SaleOutModal2'
import BillDetail3 from '../detail/BillDetail3'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from '../../bill/mixins/BillListMixin'
import { findCheckList, deleteLinkDepot } from '@/api/api'
import JDate from '@/components/jeecg/JDate'
import Vue from 'vue'

export default {
  props: ['ids','visible','id'],
  name: 'modalIndex',
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    SaleOutModal1,
    SaleOutModal2,
    BillDetail3,
    JDate,
  },
  
  data() {
    return {
      // 查询条件
      visibles:false,
      visible1:false,
      idss:'',
      idone:'',
      headerIds:'',
      num: '',
      dataSource2: [],
      width: '90%',
      title: '操作',
      isReadOnly: false,
      confirmLoading: false,
      queryParam: {
        number: '',
        searchMaterial: '',
        type: '出库',
        subType: '销售',
        roleType: Vue.ls.get('roleType'),
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      // 表头
      form: this.$form.createForm(this),
      columns: [
        {
          title: '#',
          dataIndex: 'pointNumberId',
          // key:'rowIndex',
          width: 60,
          align: 'center',
        },
        { title: '客户名称', dataIndex: 'supplierName', width: 120 },
        { title: '单据编号', dataIndex: 'billNo', width: 160 },
        { title: '商品信息', dataIndex: 'materialName', width: 220 },
        { title: '单据日期', dataIndex: 'createTime', width: 145 },
        { title: '操作员', dataIndex: 'username', width: 80 },
        { title: '金额合计', dataIndex: 'allPrice', width: 80 },
        { title: '含税合计', dataIndex: 'commodityTotalPriceAll', width: 80 },
        // { title: '收款', dataIndex: 'changeAmount',width:50},
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/depotHead/list',
        delete: '/depotHead/delete',
        deleteBatch: '/depotHead/deleteBatch',
      },
    }
  },
  computed: {},
  mounted() {
    console.log(this.ids,546)
    this.manageList()
   
  },
  created() {
    this.idss = this.ids
    this.idone =this.ids
    console.log(this.ids,547,this.id,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  },
  methods: {
   
    // 列表数据
    manageList() {
      findCheckList({
        currentPage: 1,
        pageSize: 10,
        pointId: this.ids,
      }).then((res) => {
        if (res.code === 0) {
          this.dataSource2 = res.data.row
          this.ipagination.total = res.data.total
          this.$message.success('加载成功')
        }else {
          this.$message.warning(res.message)
        }
      })
    },

    // 关闭弹窗
    guanb() {
      this.visibles = false
    },
    onClick(record) {
      console.log(record,654)
      this.visibles = true;
      // this.$nextTick(() => {
      //   this.$refs.SaleOutModal1.init()
      // })
    },
     guan() {
      this.visible1 = false
      this.close();
     },
    onClickss(record) {
      // console.log(record.headerId,65656556)
      this.headerIds = record.headerId
      this.visible1 = true

    //  this.$emit('showOrderDetail',record);
      console.log('showOrderDetail',656)
     /// this.$refs.modalDetail.show(record,'销售出库');

      this.$nextTick(() => {
        this.$refs.modalDetail.show(record,'销售出库');
      });
      // this.myHandleAdd();
     //this.myHandleDetail(record,'销售出库');

    },
    // init() {
    //   this.visible = true
    // },
    close() {
      this.$emit('guanb');
      this.$emit('fatherMethodRefresh');
      // this.searchReset();
     // this.$parent.searchReset();
     //  this.visible = false;
    },
    //删除
    handleDelete(record) {
      // console.log(record.pointNumberId,656)
      ;(this.num = record.pointNumberId),
        deleteLinkDepot({
          id: this.num,
        }).then((res) => {
          if (res.code == 0) {
            this.$message.success('删除成功')
            this.manageList();
          } else {
            that.$message.warning(res.message)
          }
        })
    },
    handleOk() {
      this.$emit('guanbi')
    },
    handleCancel() {
      // this.close()
      this.$emit('guanbi')
     // this.close();
    },
    searchReset() {
      this.queryParam = {
        type: this.queryParam.type,
        subType: this.queryParam.subType
      }
      this.searchQuery(1);
    },
    searchQuery(currentPage=1,pageSize=10){
      findCheckList({
        currentPage: currentPage,
        pageSize: pageSize,
        pointId: this.ids,
        number: this.queryParam.number,
        projectTimeStart: this.queryParam.projectTimeStart,
        projectTimeEnd: this.queryParam.projectTimeEnd
      }).then((res) => {
        if (res.code === 0) {
          this.dataSource2 = res.data.row
          this.ipagination.total = res.data.total
          this.$message.success('加载成功')
        }else {
          this.$message.warning(res.message)
        }
      })
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>